package com.lottery.ruok.lottrey.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lottery.ruok.lottrey.R;
import com.lottery.ruok.lottrey.retrofitModule.response.LiuhecaiPrizeResponse;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by ASUS on 2017/11/13.
 */

public class NumberStatisticsAdapter extends BaseAdapter {
    private ArrayList<LiuhecaiPrizeResponse> liuhecaiPrizeResponses;
    private Context mContext;

    public NumberStatisticsAdapter(ArrayList<LiuhecaiPrizeResponse> liuhecaiPrizeResponses, Context mContext) {
        this.liuhecaiPrizeResponses = liuhecaiPrizeResponses;
        this.mContext = mContext;
    }

    @Override
    public int getCount() {
        return liuhecaiPrizeResponses.size();
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public View getView(int position, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if (view != null) {
            holder = (ViewHolder) view.getTag();
        } else {
            view = LayoutInflater.from(mContext).inflate(R.layout.lhc_prize_number_item2, viewGroup, false);
            holder = new ViewHolder(view);
            view.setTag(holder);
        }

        holder.issue.setText(liuhecaiPrizeResponses.get(position).getIssue_no());
        holder.time.setText(liuhecaiPrizeResponses.get(position).getDate());

        holder.zongshuZonghe.setText(liuhecaiPrizeResponses.get(position).zonghes.get(0));
        holder.zongshuDanshuang.setText(liuhecaiPrizeResponses.get(position).zonghes.get(1));
        if (liuhecaiPrizeResponses.get(position).zonghes.get(1).equals("单")) {
            holder.zongshuDanshuang.setTextColor(mContext.getResources().getColor(R.color.purples));
        } else {
            holder.zongshuDanshuang.setTextColor(Color.parseColor("#ff6c2c"));
        }
        holder.zongshuDaxiao.setText(liuhecaiPrizeResponses.get(position).zonghes.get(2));
        if (liuhecaiPrizeResponses.get(position).zonghes.get(2).equals("小")) {
            holder.zongshuDaxiao.setTextColor(mContext.getResources().getColor(R.color.purples));
        } else {
            holder.zongshuDaxiao.setTextColor(Color.parseColor("#ff6c2c"));
        }
        if(liuhecaiPrizeResponses.get(position).zonghes.size() > 3){
            holder.zongshuQisebo.setText(liuhecaiPrizeResponses.get(position).zonghes.get(3));
            switch (liuhecaiPrizeResponses.get(position).zonghes.get(3)) {
                case "红波":
                    holder.zongshuQisebo.setTextColor(Color.parseColor("#cf5b5b"));
                    break;
                case "蓝波":
                    holder.zongshuQisebo.setTextColor(Color.parseColor("#206cec"));
                    break;
                case "绿波":
                    holder.zongshuQisebo.setTextColor(Color.parseColor("#30a125"));
                    break;
                default:
                    holder.zongshuQisebo.setTextColor(Color.parseColor("#3f3f3f"));
                    break;
            }
        }

        holder.temaDanshuang.setText(liuhecaiPrizeResponses.get(position).temas.get(0));
        switch (liuhecaiPrizeResponses.get(position).temas.get(0)) {
            case "单":
                holder.temaDanshuang.setTextColor(mContext.getResources().getColor(R.color.purples));
                break;
            case "双":
                holder.temaDanshuang.setTextColor(Color.parseColor("#ff6c2c"));
                break;
            default:
                holder.temaDanshuang.setTextColor(Color.parseColor("#3f3f3f"));
                break;
        }
        holder.temaDaxiao.setText(liuhecaiPrizeResponses.get(position).temas.get(1));
        switch (liuhecaiPrizeResponses.get(position).temas.get(1)) {
            case "小":
                holder.temaDaxiao.setTextColor(mContext.getResources().getColor(R.color.purples));
                break;
            case "大":
                holder.temaDaxiao.setTextColor(Color.parseColor("#ff6c2c"));
                break;
            default:
                holder.temaDaxiao.setTextColor(Color.parseColor("#3f3f3f"));
                break;
        }
        holder.temaHedanshuang.setText(liuhecaiPrizeResponses.get(position).temas.get(2));
        switch (liuhecaiPrizeResponses.get(position).temas.get(2)) {
            case "合单":
                holder.temaHedanshuang.setTextColor(mContext.getResources().getColor(R.color.purples));
                break;
            case "合双":
                holder.temaHedanshuang.setTextColor(Color.parseColor("#ff6c2c"));
                break;
            default:
                holder.temaHedanshuang.setTextColor(Color.parseColor("#3f3f3f"));
                break;
        }
        holder.temaHedaxiao.setText(liuhecaiPrizeResponses.get(position).temas.get(3));
        switch (liuhecaiPrizeResponses.get(position).temas.get(3)) {
            case "合小":
                holder.temaHedaxiao.setTextColor(mContext.getResources().getColor(R.color.purples));
                break;
            case "合大":
                holder.temaHedaxiao.setTextColor(Color.parseColor("#ff6c2c"));
                break;
            default:
                holder.temaHedaxiao.setTextColor(Color.parseColor("#3f3f3f"));
                break;
        }
        holder.temaWeidaxiao.setText(liuhecaiPrizeResponses.get(position).temas.get(4));
        switch (liuhecaiPrizeResponses.get(position).temas.get(4)) {
            case "尾小":
                holder.temaWeidaxiao.setTextColor(mContext.getResources().getColor(R.color.purples));
                break;
            case "尾大":
                holder.temaWeidaxiao.setTextColor(Color.parseColor("#ff6c2c"));
                break;
            default:
                holder.temaWeidaxiao.setTextColor(Color.parseColor("#3f3f3f"));
                break;
        }

        return view;
    }

    static class ViewHolder {
        @BindView(R.id.issue)
        TextView issue;
        @BindView(R.id.time)
        TextView time;
        @BindView(R.id.zongshu_zonghe)
        TextView zongshuZonghe;
        @BindView(R.id.zongshu_danshuang)
        TextView zongshuDanshuang;
        @BindView(R.id.zongshu_daxiao)
        TextView zongshuDaxiao;
        @BindView(R.id.zongshu_qisebo)
        TextView zongshuQisebo;
        @BindView(R.id.tema_danshuang)
        TextView temaDanshuang;
        @BindView(R.id.tema_daxiao)
        TextView temaDaxiao;
        @BindView(R.id.tema_hedanshuang)
        TextView temaHedanshuang;
        @BindView(R.id.tema_hedaxiao)
        TextView temaHedaxiao;
        @BindView(R.id.tema_weidaxiao)
        TextView temaWeidaxiao;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
